package order.controller;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import order.server.OrderServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import product.model.OrderInfo;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderServer orderServer;

    @Value("${spring.datasource.username}")
    String user;

    @Value("${spring.datasource.password}")
    String password;

    @Value("${spring.datasource.url}")
    String url;

    @PostConstruct
    void init() {
        log.info("配置文件 user = {} , password = {}, url = {}", user, password, url);
    }


    @RequestMapping("/{orderId}")
    public OrderInfo getOrder(@PathVariable("orderId") int orderId) {
        OrderInfo o = orderServer.getOrderById(orderId);
        log.info(o.toString());
        return o;
    }
}
